home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_39343.txt < prev    next >
Text File  |  1991-02-27  |  885b  |  29 lines

  1. -- card: 39343 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10.     void    Student::set(void)
  11.     {
  12.         scanf("%d",&student_num);    /* may cause bombs in TC with 'indirect' object */
  13.         inherited::set(); 
  14.     }
  15.  
  16. scanf() accepts the address of a variable as an argument, reads a value from the keyboard, and assigns the value to the variable pointed to by the address.  If memory is moved, this action may overwrite important data used for another purpose.  To avoid this problem, TC recommends a "shadowing" technique using local variables:
  17.  
  18.     void    Student::set(void)
  19.     {
  20.         int     temp;
  21.         scanf("%d",&temp);        /* bomb-free approach */
  22.         student_num = temp;
  23.         inherited::set(); 
  24.     }
  25.  
  26.  
  27. -- part contents for background part 7
  28. ----- text -----
  29. 124